//
//  NSDictionaryNullKiller.m
//  YYZB
//
//  Created by 顾悦 on 16/3/23.
//
//

#import "NSDictionaryNullKiller.h"

@implementation NSDictionaryNullKiller

+ (id)dataByReplacingNullWithEmptyString:(id)data {
    if ([data isKindOfClass:[NSDictionary class]]) {
        
        NSMutableDictionary *temp = [data mutableCopy];
        for (NSString *key in temp.allKeys) {
            id subData = temp[key];
            temp[key] = [NSDictionaryNullKiller dataByReplacingNullWithEmptyString:subData];
        }
        
        return temp;
        
    } else if ([data isKindOfClass:[NSArray class]]) {
        
        NSMutableArray *array = [data mutableCopy];
        for (NSInteger i = 0; i < array.count; i++) {
            id subData = array[i];
            subData = [NSDictionaryNullKiller dataByReplacingNullWithEmptyString:subData];
            [array replaceObjectAtIndex:i withObject:subData];
        }
        
        return array;
        
    } else if ([data isKindOfClass:[NSString class]]){
        return data;
    } else if (data == [NSNull null] || [data isKindOfClass:[NSNull class]]) {
        return @"";
    } else {
        return data;
    }
}

@end
